﻿
// 获取当前时间
var date = new Date();
var expiresDays = 1;
// 将date设置为1天以后的时间
date.setTime(date.getTime() + 30 * 1000);//expiresDays * 24 * 3600 * 1000

// 写cookies
function addCookie(name, value, expiresDays) {
    var cookieString = name + " = " + escape(value);
    cookieString = cookieString + "; expires = " + date.toGMTString();
    document.cookie = cookieString;
}

//读取cookies
function getCookie(name) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split(";");
    for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split("=");
        if (arr[0].indexOf(name) > -1) return arr[1];
    }
    return "";
}

function recordvisitcount() {
    

    var wxcode = document.querySelector(".wxcode");
    //var key = location.pathname.substr(1);
    if (wxcode) {
        var counter = getCookie(wxcode.innerText);
        if (!counter) counter = 1;
        else counter = parseInt(counter) + 1;
        addCookie(wxcode.innerText, counter, date);
        //addCookie(key, wxcode, date);
        console.log("您好，这是您第" + counter + "次浏览本页面！");
    }
}

if (window.addEventListener) {//FF下使用
    window.addEventListener("load", recordvisitcount, false);
} else if (window.attachEvent) {//IE下使用
    window.attachEvent("onload", recordvisitcount);
}

